package com.example.demo.controller;

import com.example.demo.entity.Team;
import com.example.demo.service.TeamDashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@RequestMapping("/api/dashboard")
@CrossOrigin(origins = "*")
public class TeamDashboardController {

    @Autowired
    private TeamDashboardService dashboardService;

    @GetMapping("/{id}")
    public ResponseEntity<Team> getTeamById(@PathVariable Long id) {
        Optional<Team> team = dashboardService.findById(id);
        return team.map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    /**
     * 获取团队数据看板
     */
    @GetMapping("/team/{teamId}")
    public ResponseEntity<TeamDashboardVO> getTeamDashboard(@PathVariable Long teamId) {
        TeamDashboardVO dashboard = dashboardService.getTeamDashboard(teamId);
        return ResponseEntity.ok(dashboard);
    }

    /**
     * 获取个人在团队中的贡献度
     */
    @GetMapping("/team/{teamId}/contribution/{studentId}")
    public ResponseEntity<MemberContributionVO> getMemberContribution(
            @PathVariable Long teamId,
            @PathVariable Long studentId) {
        MemberContributionVO contribution = dashboardService.getMemberContribution(teamId, studentId);
        return ResponseEntity.ok(contribution);
    }
}